package com.example.yichuangyun.mvvm.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.DataBindingHolder;
import com.example.yichuangyun.R;
import com.example.yichuangyun.databinding.ItemIncomePayBinding;
import com.example.yichuangyun.model.order.IncomePayDataModel;
import com.example.yichuangyun.utils.CommonUtil;

public class IncomePayAdapter extends BaseQuickAdapter<IncomePayDataModel.IncomePayModel, DataBindingHolder<ItemIncomePayBinding>> {
    private final String[] types = new String[]{"银行转账", "微信", "支付宝", "兴e付", "现金", "OK卡"};

    @SuppressLint("SetTextI18n")
    @Override
    protected void onBindViewHolder(@NonNull DataBindingHolder<ItemIncomePayBinding> itemIncomePayBindingDataBindingHolder, int i, @Nullable IncomePayDataModel.IncomePayModel incomePayModel) {
        ItemIncomePayBinding binding = itemIncomePayBindingDataBindingHolder.getBinding();
        binding.setIncomePayModel(incomePayModel);
        if (incomePayModel != null) {
            // 0收款 1支出
            if (incomePayModel.getType() == 0) {
                if (incomePayModel.getCollectType() - 10 >= 0) {
                    binding.tvWay.setText(incomePayModel.getCollectType() != -1
                            ? types[incomePayModel.getCollectType() - 10] + " > " + incomePayModel.getCollectAccount()
                            : CommonUtil.setText(incomePayModel.getCollectAccount()));
                } else {
                    binding.tvWay.setText("/");
                }
            } else {
                if (incomePayModel.getPayType() - 10 >= 0) {
                    binding.tvWay.setText(incomePayModel.getPayType() != -1
                            ? types[incomePayModel.getPayType() - 10] + " > " + incomePayModel.getPayAccount()
                            : CommonUtil.setText(incomePayModel.getPayAccount()));
                } else {
                    binding.tvWay.setText("/");
                }
            }
        }
    }

    @NonNull
    @Override
    protected DataBindingHolder<ItemIncomePayBinding> onCreateViewHolder(@NonNull Context context, @NonNull ViewGroup viewGroup, int i) {
        return new DataBindingHolder<>(R.layout.item_income_pay, viewGroup);
    }
}
